package com.java.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: wjr
 * @Description:
 * @Date Created in  2020-09-02 2:07
 * @Modified By:
 */
@WebServlet(value = "/testCookie")
public class CookieServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //创建cookie
        Cookie cookie = new Cookie("cookie1", "cookieTest");
        //将cookie响应给客户端
        resp.addCookie(cookie);
        //页面跳转
        resp.sendRedirect("show.jsp");
    }
}
